<?php

namespace app\admin\model\finance\extract;

use think\Model;
use think\Cache;
class Season extends Model
{
    // 表名
    protected $name = 'finance_extract_season';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
		'province_text',
        'city_text',
        'area_text',
        'reg_level_text',
       'lecturer_text',
       'lecturer_avatar_text',
       'subject_text'
    ];
     /**
     * 讲师头像
     */
    public function getLecturerAvatarTextAttr($value, $data){
        $value = $value ? $value : $data['lecturer_id'];
        $avatar = TableField('Admin','thumb_avatar',$value,'userid');
        $avatar = $avatar ? $avatar : TableField('Admin','avatar',$value,'userid');
        $avatar = $avatar ? $avatar : '/dailybill/img/jia.png';
        return $avatar;
    }    
     /**
     * 讲师姓名
     */
    public function getLecturerTextAttr($value, $data){
        $value = $value ? $value : $data['lecturer_id'];
        $username = TableField('Admin','username',$value,'userid');
        return $username;
    }   
     /**
     * 讲师姓名
     */
    public function getSubjectTextAttr($value, $data){
        $value = $value ? $value : $data['subject_id'];
        $name = TableField('Subject','name',$value,'id');
        return $name;
    }   
	 /**
     * 获取省的名称
     * @return array
     */
    public function getProvinceOrderList()
    {
        if(!$list = \think\Cache::get('arealist'))
        {
            $area = model(GetTableModel('Area'))::field('id,name')->select();
            $area = collection($area)->toArray();
            $list = array_column($area,'name','id');
            Cache::set('areaList',$list,0);//设置0永久缓存不过期
        }
        return $list;
    }
     public function getProvinceTextAttr($value, $data)
    {
        $value = $value ? $value : $data['province'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCityTextAttr($value, $data)
    {
        $value = $value ? $value : $data['city'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getAreaTextAttr($value, $data)
    {
        $value = $value ? $value : $data['area'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	 
    public function getRegLevelList()
    {
        return ['A' => __('Season.Reg_level A'),'B' => __('Season.Reg_level B'),'C' => __('Season.Reg_level C')];
    }     
	public function getRegLevelTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['reg_level'];
        $list = $this->getRegLevelList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    







}
